// ==UserScript==
// @name           Ikariam Cultural Diplomacy Fix
// @namespace      overkill_gm
// @description    Fixes Culture Subject Line
// @include        http://*.ikariam.org/*
// @exclude        http://board.ikariam.org
// ==/UserScript==

// homepage: http://userscripts.org/scripts/show/28642
// this code could be a lot smaller, but I am lazy. This is plenty small.

function debug(aMsg) { setTimeout(function() { throw new Error("[debug] " + aMsg); }, 0);}

$ = document.getElementById;

function $x( xpath, root ) {
  var doc = root ? root.evaluate ? root : root.ownerDocument : document, next;
  var got = doc.evaluate( xpath, root||doc, null, 0, null ), result = [];
  switch (got.resultType) {
    case got.STRING_TYPE:
      return got.stringValue;
    case got.NUMBER_TYPE:
      return got.numberValue;
    case got.BOOLEAN_TYPE:
      return got.booleanValue;
    default:
      while (next = got.iterateNext())
        result.push( next );
      return result;
  }
}
function $X( xpath, root ) {
  var got = $x( xpath, root );
  return got instanceof Array ? got[0] : got;
}

var temp;

if (temp = $X("//select[@id='treaties']/option[@value='0']")) {
  if (temp.firstChild.nodeValue.search(/Cultural/) != -1) temp.firstChild.nodeValue = "Cancel Cultural Assets Treaty";
}
if (temp = $X("//select[@id='treaties']/option[@value='1']")) {
  if (temp.firstChild.nodeValue.search(/Cultural/) != -1) temp.firstChild.nodeValue = "Cancel Cultural Assets Treaty";
}
if (temp = $X("//select[@id='treaties']/option[@value='2']")) {
  if (temp.firstChild.nodeValue.search(/Cultural/) != -1) temp.firstChild.nodeValue = "Request Cultural Assets Treaty";
}
